import router from "./index"
import { get } from "@/utils/auth"

const allowList = [
    '/login',
    '/register'
]

router.beforeEach((to, from, next) => {
    const token = get()
    if (token) {
        if (to.path === '/login') {
            next({
                path: '/',
            })
        } else {
            next()
        }
    } else if (allowList.includes(to.path)) {
        next()
    } else {
        next({
            path: '/login',
            query: {},
            replace: true
        })
    }

})